package com.zp.qualitypractice.list.demo;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;

import com.zp.qualitypractice.R;
import com.zp.qualitypractice.list.OnPullLoadListener;
import com.zp.qualitypractice.list.RefreshLoadSwipeLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by izp on 2017/5/2.
 */

public class RefreshSwipeLayoutActivity extends AppCompatActivity {
    private List<SwipeDate> list = new ArrayList<>();
    private RefreshLoadSwipeLayout mRefreshLoadSwipeLayout;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refresh_swipe);
        mRefreshLoadSwipeLayout = (RefreshLoadSwipeLayout) findViewById(R.id.refreshLoadSwipeLayout);
        initData();
    }

    private void initData() {
        for (int i = 0; i < 20; i++) {
            SwipeDate swipeDate = new SwipeDate();
            swipeDate.name = "于" + i;
            swipeDate.type = 1;
            list.add(swipeDate);
        }
        final RefreshLoadSwipeAdapter demoAdapter = new RefreshLoadSwipeAdapter(list);
        mRefreshLoadSwipeLayout.setLayoutManager(new LinearLayoutManager(this));
        mRefreshLoadSwipeLayout.setAdapter(demoAdapter);
        mRefreshLoadSwipeLayout.setRefreshAndLoadMoreListener(new OnPullLoadListener() {
            @Override
            public void onRefreshing() {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        mRefreshLoadSwipeLayout.refreshComplete();
                    }
                }, 2500);
            }

            @Override
            public void onLoading() {
                Log.i("加载更多", "000");
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        mRefreshLoadSwipeLayout.setloadMoreComplete();
                    }
                }, 2500);
            }
        });
    }
    class SwipeDate {
        public int type;
        public String name;
    }
}
